package com.yanqu.road.server.cmd.monopolymarket.fortress;

import com.yanqu.road.entity.monopolymarket.MonopolyMarket;
import com.yanqu.road.pb.monopolymarket.MonopolyMarketProto;
import com.yanqu.road.server.cmd.CrossCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.manager.monopolymarket.MonopolyMarketFortressMgr;
import com.yanqu.road.server.manager.monopolymarket.MonopolyMarketMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.CrossProtocol;

import java.util.List;

/**
 * @Description
 * @Author cwq
 * @Data 2021/10/15 16:32
 */
@Cmd(code = CrossProtocol.C_MONOPOLY_MARKET_FORTRESS_SYN_INFO, desc = "边关要塞 派遣期 同步 联盟信息退盟、解散")
public class CrossMonopolyMarketFortressSynInfoCmd extends CrossCommand {

    private int type;
    private long userId ;
    private String unionId ;
    private String unionName ;
    private List<MonopolyMarketProto.MonopolyMarketFortressLockUnionInfoEntity> lockUnionList;
    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        MonopolyMarketProto.MonopolyMarketFortressSynInfoToCrossMsg req = MonopolyMarketProto.MonopolyMarketFortressSynInfoToCrossMsg.parseFrom(packet.getBytes());
        type = req.getType();
        userId = req.getUserId();
        unionId = req.getUnionId();
        unionName = req.getUnionName();
        lockUnionList = req.getLockUnionListList();
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        MonopolyMarket monopolyMarket = MonopolyMarketMgr.getMonopolyMarket(serverId,true);
        if(monopolyMarket == null){
            return;
        }
        synchronized (monopolyMarket){
            switch (type){
                case 0:
                    // 0解散联盟
                    MonopolyMarketFortressMgr.deleteUnion(monopolyMarket,unionId);
                    break;
                case 1:
                    // 1玩家退盟
                    MonopolyMarketFortressMgr.leaveUnion(monopolyMarket,unionId,userId);
                    break;
                case 2:
                    // 2锁定联盟信息
                    MonopolyMarketFortressMgr.lockUnionInfo(monopolyMarket,serverId,lockUnionList);
                    break;
                case 3:
                    // 3联盟改名
                    MonopolyMarketFortressMgr.changeUnionName(monopolyMarket,unionId,unionName);
                    break;
                default:
                    break;
            }
        }
    }

    @Override
    public void sendData() {

    }
}
